package com.west.utils;

import java.util.Scanner;

public class ScannerChoice {
	/**
	 * 键盘获取商品价格。小数点后两位
	 */
	public static double ScannerInfo() {
		double num=0.00;
		do {
			Scanner sc = new Scanner(System.in);
			System.out.println("保留小数点后两位，请输入");
			String info = sc.next();
			String regex = "(([1-9][0-9]*)\\.([0-9]{2}))|[0]\\.([0-9]{2})";//保留小数点后2位小数
			if(info.matches(regex)) {
				num=Double.parseDouble(info);
			}else {
				System.err.println("!输入有误");
				continue;
			}
			break;
		}while(true);
		return num;
	}
	
	/**
	 * 键盘获取商品数量
	 */
	public static int ScannerNum() {
		int num=0;
		String regex = "([1-9])|([1-9][0-9]+)";//商品数量
		do {
			Scanner sc = new Scanner(System.in);
			System.out.println("请输入： ");
			String nums = sc.next();
			
			if(nums.matches(regex)) {
				num=Integer.parseInt(nums);
			}else {
				System.err.println("!输入错误");
				continue;
			}
			break;
		}while(true);
		return num;
	}
	
	/**
	 * 获取键盘输入
	 */
	public static String ScannerInfoString() {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入");
		return sc.next();
	}
	
	
	
	
}
